#按logic执行计算
"""
金叉：2，死叉：-2  向上：1  向下：-1
支持重复计算，但是要指定timekey，只能向前重复计算




"""
from research.calcor.calcor_logic import logic_calc
class signal_filter_bylogic:
    def __init__(self,signal1,signal2):
        self.signal1=signal1
        self.signal2=signal2
        self.pre_signal1=0
    def oncalc(self,b,timekey=None):
        rst=0
        if self.signal1 in b.keys():
            s1=b[self.signal1]
            isupdate=True
            if self.signal2 in b.keys():
                s2=b[self.signal2]
                if self.pre_signal1==2:
                    if s2==2:
                        rst=2
                        isupdate = True
                    else:
                        rst=1
                        isupdate = False
                elif self.pre_signal1==-2:
                    if s2==-2:
                        rst=-2
                        isupdate = True
                    else:
                        rst=-1
                        isupdate = False
                else:
                    isupdate = True

                if isupdate:
                    self.pre_signal1 = s1

        return rst